﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PrinteMaster
{
    public partial class 系统设置 : Form
    {
        public 系统设置()
        {
            InitializeComponent();
        }

        private void 系统设置_Load(object sender, EventArgs e)
        {
            //控制日期或时间的显示格式
            dateTimePicker1.CustomFormat = "HH:mm:ss";
            //使用自定义格式
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            //时间控件的启用
            dateTimePicker1.ShowUpDown = true;

            DataBase.getInstance().getSystemSetting();

            dateTimePicker1.Value = DataBase.SyetemSetting.time;
            textBox等待时间.Text = DataBase.SyetemSetting.m_WaitTimeSec.ToString();
            if (DataBase.SyetemSetting.m_autoPayState == DataBase.SyetemSetting.AutoPay.开启)
                checkBox自助充值.Checked = true;
            else
                checkBox自助充值.Checked = false;
            textBox分钟.Text = DataBase.SyetemSetting.Min.ToString();
            textBox毛钱.Text = (DataBase.SyetemSetting.MoneySub).ToString();
            textBox优惠码.Text = DataBase.SyetemSetting.code;
            textBox1.Text = (DataBase.SyetemSetting.codeMoney*10.0).ToString("0.00");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DataBase.SyetemSetting.AutoPay auto = DataBase.SyetemSetting.AutoPay.未开启;
            if(checkBox自助充值.Checked)
                auto = DataBase.SyetemSetting.AutoPay.开启;

            var money = Convert.ToDouble(textBox1.Text);


            DataBase.Error er = DataBase.getInstance().setSystemSetting(
                dateTimePicker1.Value,
                Convert.ToUInt32(textBox等待时间.Text), auto,
                Convert.ToUInt32(textBox分钟.Text),Convert.ToUInt32(textBox毛钱.Text),textBox优惠码.Text,(money/10.0).ToString("0.00"));

            if (er != DataBase.Error.ok)
                MessageBox.Show("修改失败，失败原因=>" + er);
            else
            {
                MessageBox.Show("修改成功!");
                this.Close();
            }


        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            Function.inputInt(sender, e);
        }
    }
}
